package org.grottarossa.ui.core.container;


import java.io.Serializable;
import java.util.ResourceBundle;

import org.grottarossa.template.data.pojo.content.Content;
import org.grottarossa.template.data.pojo.content.ContentList;
import org.grottarossa.ui.core.i18n.DM;

import com.vaadin.data.util.HierarchicalContainer;

public class ContentContainer extends HierarchicalContainer implements Serializable
{
	private static ResourceBundle m_localizer = DM.instance().getBundle(ContentContainer.class.getName());
	private static final long serialVersionUID = 5628926286891641946L;

	private String DISPLAYNAME = m_localizer.getString("container.columns.displayname");
	private String [] m_visibleColumns = { DISPLAYNAME };

	public ContentContainer(ContentList contentList)
	{
		super();

		addContainerProperty(DISPLAYNAME, String.class, null);
		addContainerProperty("contentID", Integer.class, null);

		Object parent = null;
		int i=0;

		for( Content content : contentList)
		{
			Object obj = addItem();
			getContainerProperty(obj, DISPLAYNAME).setValue(content.getDisplayName());
			getContainerProperty(obj, "contentID").setValue(i);
			i++;

			if ( content.isSection() )
				parent = obj;
			else if ( parent != null)
			{
				setParent(obj, parent);
				setChildrenAllowed(obj, false);
			}
		}
	}

	public String[] getVisibleColumns()
	{
		return m_visibleColumns;
	}
}
